<?php

/**
 * This is the model class for table "sys_member_activation_request".
 *
 * The followings are the available columns in table 'sys_member_activation_request':
 * @property integer $member_activation_request_id
 * @property integer $member_activation_request_network_id
 * @property integer $member_activation_request_quantity
 * @property string $member_activation_request_note
 * @property string $member_activation_request_status
 * @property string $member_activation_request_datetime
 */
class sys_member_activation_request extends CActiveRecord {

    public $member_name;
    public $member_mobilephone;
    public $network_mid;
    public $member_activation_end_date;

//    public $member_activation_request_id;
//    public $member_activation_request_network_id;
//    public $member_activation_request_quantity;
//    public $member_activation_request_status;
//    public $member_activation_request_note;
//    public $member_activation_request_datetime;
    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'sys_member_activation_request';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('member_activation_request_quantity, member_activation_request_datetime', 'required'),
            array('member_activation_request_network_id, member_activation_request_quantity', 'numerical', 'integerOnly' => true),
            array('member_activation_request_status', 'length', 'max' => 8),
            array('member_activation_request_note', 'safe'),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('member_activation_request_id, member_activation_request_network_id, member_activation_request_quantity, member_activation_request_note, member_activation_request_status, member_activation_request_datetime', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'member_activation_request_id' => 'Member Activation Request',
            'member_activation_request_network_id' => 'Member Activation Request Network',
            'member_activation_request_quantity' => 'Member Activation Request Quantity',
            'member_activation_request_note' => 'Member Activation Request Note',
            'member_activation_request_status' => 'Member Activation Request Status',
            'member_activation_request_datetime' => 'Member Activation Request Datetime',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('member_activation_request_id', $this->member_activation_request_id);
        $criteria->compare('member_activation_request_network_id', $this->member_activation_request_network_id);
        $criteria->compare('member_activation_request_quantity', $this->member_activation_request_quantity);
        $criteria->compare('member_activation_request_note', $this->member_activation_request_note, true);
        $criteria->compare('member_activation_request_status', $this->member_activation_request_status, true);
        $criteria->compare('member_activation_request_datetime', $this->member_activation_request_datetime, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    public function search2() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;
        $criteria->select = 't.member_activation_request_quantity,t.member_activation_request_note,t.member_activation_request_datetime,
                            mm.member_name,mm.member_mobilephone,mn.network_mid,mma.member_activation_end_date';
        $criteria->join = 'LEFT JOIN  sys_network mn ON mn.network_id=t.member_activation_request_network_id
                           LEFT JOIN sys_member mm ON mm.member_network_id=t.member_activation_request_network_id 
                           LEFT JOIN sys_member_activation mma ON t.member_activation_request_network_id=mma.member_activation_network_id';




        $criteria->compare('member_activation_request_id', $this->member_activation_request_id);
        $criteria->compare('member_activation_request_network_id', $this->member_activation_request_network_id);
        $criteria->compare('member_activation_request_quantity', $this->member_activation_request_quantity);
        $criteria->compare('member_activation_request_note', $this->member_activation_request_note, true);
        $criteria->compare('member_activation_request_status', $this->member_activation_request_status, true);
        $criteria->compare('member_activation_request_datetime', $this->member_activation_request_datetime, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
    
    
    public function search_unpaid() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;
        $criteria->select = 't.member_activation_request_id,t.member_activation_request_quantity,t.member_activation_request_note,t.member_activation_request_datetime,
                            mm.member_name,mm.member_mobilephone,mn.network_mid,mma.member_activation_end_date';
        $criteria->join = 'LEFT JOIN  sys_network mn ON mn.network_id=t.member_activation_request_network_id
                           LEFT JOIN sys_member mm ON mm.member_network_id=t.member_activation_request_network_id 
                           LEFT JOIN sys_member_activation mma ON t.member_activation_request_network_id=mma.member_activation_network_id';

        


        $criteria->compare('member_activation_request_id', $this->member_activation_request_id);
        $criteria->compare('member_activation_request_network_id', $this->member_activation_request_network_id);
        $criteria->compare('member_activation_request_quantity', $this->member_activation_request_quantity);
        $criteria->compare('member_activation_request_note', $this->member_activation_request_note, true);
        $criteria->compare('member_activation_request_status','unpaid');
        $criteria->compare('member_activation_request_datetime', $this->member_activation_request_datetime, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
    
    public function search_paid() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;
        $criteria->select = 't.member_activation_request_id,t.member_activation_request_quantity,t.member_activation_request_note,t.member_activation_request_datetime,
                            mm.member_name,mm.member_mobilephone,mn.network_mid,mma.member_activation_end_date';
        $criteria->join = 'LEFT JOIN  sys_network mn ON mn.network_id=t.member_activation_request_network_id
                           LEFT JOIN sys_member mm ON mm.member_network_id=t.member_activation_request_network_id 
                           LEFT JOIN sys_member_activation mma ON t.member_activation_request_network_id=mma.member_activation_network_id';




        $criteria->compare('member_activation_request_id', $this->member_activation_request_id);
        $criteria->compare('member_activation_request_network_id', $this->member_activation_request_network_id);
        $criteria->compare('member_activation_request_quantity', $this->member_activation_request_quantity);
        $criteria->compare('member_activation_request_note', $this->member_activation_request_note, true);
        $criteria->compare('member_activation_request_status','paid');
        $criteria->compare('member_activation_request_datetime', $this->member_activation_request_datetime, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
    
    public function search_report() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;
        $criteria->select = 't.member_activation_request_id,t.member_activation_request_quantity,t.member_activation_request_note,t.member_activation_request_datetime,
                            mm.member_name,mm.member_mobilephone,mn.network_mid,mma.member_activation_end_date';
        $criteria->join = 'LEFT JOIN  sys_network mn ON mn.network_id=t.member_activation_request_network_id
                           LEFT JOIN sys_member mm ON mm.member_network_id=t.member_activation_request_network_id 
                           LEFT JOIN sys_member_activation mma ON t.member_activation_request_network_id=mma.member_activation_network_id';




        $criteria->compare('member_activation_request_id', $this->member_activation_request_id);
        $criteria->compare('member_activation_request_network_id', $this->member_activation_request_network_id);
        $criteria->compare('member_activation_request_quantity', $this->member_activation_request_quantity);
        $criteria->compare('member_activation_request_note', $this->member_activation_request_note, true);
        $criteria->compare('member_activation_request_status','approved');
        $criteria->compare('member_activation_request_datetime', $this->member_activation_request_datetime, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
    
    

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return sys_member_activation_request the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

}
